﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Estimate
{
    public partial class formMain : Form
    {
        Root root;

        public formMain(Root root)
        {
            this.root = root;
            root.MDIParent = this;

            InitializeComponent();
            Icon = Estimate.Properties.Resources.MainIcon;

            if (root.UserRule == UserRules.Trader) InitTrader();

            foreach (ToolStripMenuItem titleItem in menu.Items)
                foreach (ToolStripMenuItem item in titleItem.DropDownItems )
                    item.Click += new EventHandler(menuItem_Click);
        }

        void menuItem_Click(object sender, EventArgs e)
        {
            ToolStripMenuItem menuItem = (ToolStripMenuItem)sender;
            string formName = menuItem.Name.Substring(17);
            Type tObj = Type.GetType(String.Format("{0}.form{1}", Application.ProductName, formName));
            if (tObj == null) { formMain.ShowError("Форму Незнайдено"); return; }
            FormMDIChildTemplate form = (FormMDIChildTemplate)Activator.CreateInstance(tObj);
            form.Text = menuItem.Text;
            root.ShowForm(form);
        }

        private void InitTrader()
        {
            toolStripMenuItemAdmin.Visible = false;
        }

        #region Show
        public static void ShowError(string Message)
        { MessageBox.Show(Message, "Помилка!", MessageBoxButtons.OK, MessageBoxIcon.Error); }

        public static void ShowInformation(string Message)
        { MessageBox.Show(Message, "Інформація!", MessageBoxButtons.OK, MessageBoxIcon.Information); }
        #endregion
   
    }
}
